package com.groupbuying.sysconfig.dto.mini;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.List;

/**
 * @Author Vincentxin
 * @Date 2019/10/24
 */
public class DataFormatForWeChatMini {

    public static JSONObject create(MiniWechatInfo miniWechatInfo){
        JSONObject messageJson = new JSONObject();
        messageJson.put("touser", miniWechatInfo.getToUser());
        messageJson.put("template_id", miniWechatInfo.getTemplateId());
        messageJson.put("page", miniWechatInfo.getPage());
        messageJson.put("form_id", miniWechatInfo.getFormId());
        JSONObject dataJson = new JSONObject();
        messageJson.put("data", dataJson);
        for (MiniDataInfo datum : miniWechatInfo.getData()) {
            JSONObject dataTem = new JSONObject();
            dataTem.put("value", datum.getValue());
            dataJson.put(datum.getName(), dataTem);
        }
        return messageJson;
    }
}
